/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.edit.policies;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.BendpointEditPolicy;
import org.eclipse.gef.requests.BendpointRequest;

import edu.pku.sei.modeler.commands.AddBendpointCommand;
import edu.pku.sei.modeler.commands.DeleteBendpointCommand;
import edu.pku.sei.modeler.commands.MoveBendpointCommand;
import edu.pku.sei.modeler.model.structure.MetaLink;

/**
 * @author zl
 *
 */
public class LinkBendpointEditPolicy extends BendpointEditPolicy {

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.BendpointEditPolicy#getCreateBendpointCommand(org.eclipse.gef.requests.BendpointRequest)
	 */
	protected Command getCreateBendpointCommand(BendpointRequest request) {
		Point loc = request.getLocation();
		getConnection().translateToRelative(loc);
		return new AddBendpointCommand((MetaLink)request.getSource().getModel(), 
				loc, request.getIndex());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.BendpointEditPolicy#getDeleteBendpointCommand(org.eclipse.gef.requests.BendpointRequest)
	 */
	protected Command getDeleteBendpointCommand(BendpointRequest request) {
		return new DeleteBendpointCommand((MetaLink)getHost().getModel(), request.getIndex());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.BendpointEditPolicy#getMoveBendpointCommand(org.eclipse.gef.requests.BendpointRequest)
	 */
	protected Command getMoveBendpointCommand(BendpointRequest request) {
		Point loc = request.getLocation();
		getConnection().translateToRelative(loc);
		return new MoveBendpointCommand((MetaLink)request.getSource().getModel(),
				loc, request.getIndex());
	}

}
